package com.hhly.rabbitmq.publish_subscribe;
import java.io.IOException;

import com.hhly.rabbitmq.RabbitMQUtil;
import com.rabbitmq.client.Channel;

public class EmitLog {

    public  static final String EXCHANGE_NAME = "logs";

    public static void main(String[] argv)
                  throws java.io.IOException {
        try {
			Channel channel = RabbitMQUtil.getChannel();
			channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
			int i = 0;
			for(;;){
				Thread.sleep(1000);
				String message = "Hello World!" + i++;
				 channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
			     System.out.println(" [x] Sent '" + message + "'");
			}
		} catch (IOException | InterruptedException e) {
			e.printStackTrace();
		}
    }
}